<!-- Teacher_StudyCourseChapter.html -->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
	<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
	<title>mocc课程章节</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/mui.min.css" />
	<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
	<!-- <link rel="stylesheet" href="../../css/base.css"/> -->
	<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
	<style type="text/css">
		.weui_panel .chapter_cell_icon{
			width:20px;
			height: 20px;
			background-size: 20px 20px;
			margin: 0;
		}
		.chapter_content_cell{
			padding-left: 30px;
		}
		.weui_panel .cell-right-arrow{
			width:20px;
			height: 20px;
			background-size: 20px 20px;
			margin: 0;
			float: right;
		}
		.arrow-down{
			background-image: url(../../image/arrow_down.png);
		}
		.arrow-right{
			background-image: url(../../image/arrow_right.png);
		}
		.doc_unstudy{
			background-image: url(../../image/doc_icon.png);
		}
		.doc_studying{
			background-image: url(../../image/doc_icon_studying.png);
		}
		.doc_studied{
			background-image: url(../../image/doc_icon_studied.png);
		}
		.video_unstudy{
			background-image: url(../../image/video_icon.png);
		}
		.video_studying{
			background-image: url(../../image/video_icon_studying.png);
		}
		.video_studied{
			background-image: url(../../image/video_icon_studied.png);
		}
		.richtext_unstudy{
			background-image: url(../../image/richtext_unstudy.png);
		}
		.richtext_studying{
			background-image: url(../../image/richtext_studying.png);
		}
		.richtext_studied{
			background-image: url(../../image/richtext_studied.png);
		}
		.ziyuan_unstudy{
			background-image: url(../../image/ziyuan_icon_unstudy.png);
		}
		.ziyuan_studying{
			background-image: url(../../image/ziyuan_icon_studying.png);
		}
		.ziyuan_studied{
			background-image: url(../../image/ziyuan_icon_studied.png);
		}
		.tests_untest{
			background-image: url(../../image/study_test.png);
		}
		.tests_tested{
			background-image: url(../../image/study_tested.png);
		}
		.taolun_normal{
			background-image: url(../../image/icon_taolun_normal.png);
		}

		.works{
			background-image: url(../../image/study_test.png);
		}
		.taolun_highlight{
			background-image: url(../../image/icon_taolun_highlight.png);
		}
		.downloaded{
			background-image: url(../../image/icon_download_finish.png);
		}
		.download_progress{
			background-color: rgba(4,190,2,0.25);
			height:100%;
			width:0;
			position:absolute;
			left: 0;
			top:0;
		}
		.chapter_title{
			font-size: 14px;
			padding-left: 10px;
			padding-right: 10px;
			color: #393939;
		}
		.list_section_contnt{
			font-size: 16px;
			color: #454545;
			background-color: #f9f9f9;
			margin-bottom: 0;
		}
		.chapter_etime{
			margin-right: 10px;
			font-size: 14px;
		}
		.noSign{
			width: auto;
		}
		.loadFailure{
			width: auto;
		}
		.weui_panel .weui_btn{
			background-color: #1da4e8;
			border-color: #1da4e8;
			width: 44px;
			margin-left: 10px;
			border-radius: 2px;
			font-size: 12px;
			line-height: 24px;
		}
		.weui_panel .weui_btn:active{
			background-color: #0d94d8;
			border-color: #0d94d8;
			color: white;
		}
		.weui_panel .right-btn{
			float: right;
		}
		.weui_panel .right-btn-cancel{
			background-color: #CAC2C2;
			border-color: #CAC2C2;
		}
		.weui_panel .right-btn-cancel:active{
			background-color: #BAB2B2;
			border-color: #BAB2B2;
		}
		.weui_panel .weui_btn+.weui_btn{
			margin: 0;
		}
		.base_style_text_color .chapter_title{
			color: #18b4ed;
		}
		.base_style_text_color .chapter_time{
			color: #18b4ed;
		}
		.chapter_time{
			font-size: 12px;
			color: #1da4e8;
		}
		.right-switch{
			float: right;
			margin-left: 10px;
		}
		.mui-switch-mini {
		    width: 42px;
		}
		.mui-switch {
			height: 25px;
		}
		.mui-switch .mui-switch-handle{
			width: 22px;
			height: 22px;
		}
		/*.mui-switch.mui-active {
		    border-color: #18b4ed;
		    background-color: #18b4ed;
		}*/
		.weui_cells_title{
			margin-top: 0px;
			margin-bottom: 0px;
		}
		.title-span{
			text-overflow:ellipsis;
			overflow:hidden;
			white-space:nowrap;
			width:-webkit-calc(100% - 52px); 
			width:-moz-calc(100% - 52px); 
			width:calc(100% - 52px); 
		}
		.footer-view{
			position: fixed;
			left: 0;
			bottom: 0;
			margin: 0;
			width: 100%;
			height: 50px;
			padding: 0;
			z-index: 99;
		}
		.footer-view .mui-btn-block{
			width: 100%;
			height: 100%;
			margin: 0;
			padding: 0;
			background-color: #18b4ed;
			border-color: #18b4ed;
			color: white;
			font-size: 16px;
		}
		.footer-view .mui-btn-block:active{
			background-color: #18b4ed;
		}
		.mui-btn, button{
			border-radius: 0px;
		    border-top-left-radius: 0px; 
		    border-top-right-radius: 0px; 
		    border-bottom-right-radius: 0px; 
		    border-bottom-left-radius: 0px; 
		} 
		.blank-div{
			height: 50px;
		}
		.add-btn-div{
			position: fixed;
			right: 100px;
			bottom: 50px;
			width: 80px;
			height: 80px;
		}
		.add-btn{
			width: 100%;
			height: 100%;
		}
		.weui_btn:after {
			border: 1px solid #18b4ed;
		}
		.weui_panel_hd:after {
		    border-bottom: 1px solid #ededed;
		    color: #ededed;
		    -webkit-transform: scaleY(.3);
		    transform: scaleY(.3);
		    left: 0;
		}
	</style>
</head>
<body>
	<div class="noSign noDataDiv" hidden="hidden" id="noData">
		<img src="../../image/icon_img.png" width="60%">
		<p class="font16 top_15 base_dark_grey" >
			暂无数据
		</p>
	</div>
	<div class="loadFailure noInternetDiv" hidden="hidden" id="noNet">
		<img src="../../image/icon_img01.png" width="60%">
		<p class="" >
			数据加载失败
		</p>
		<p>
			请检查您的网络
		</p>
		<button type="button" class="mui-btn mui-btn-outlined" onclick="loadData()">
			重新加载
		</button>
	</div>
	<div class="weui_panel" style="margin-top: 0;">
		<div id="chapter_content">

			<!-- <div class="weui_panel_hd list_section_contnt">
				<span class="title-span">
					第一章第一章第一章第一章第一章
					第一章第一章第一章第一章第一章
				</span>
				<div class="mui-switch mui-switch-mini right-switch">
					<div class="mui-switch-handle"></div>
				</div>
			</div>
			<div class="weui_cell weui_cells_title">
				<span class="title-span">
					第一节第一节第一节第一节第一节
					第一节第一节第一节第一节第一节
				</span>
				<div class="mui-switch mui-switch-mini right-switch">
					<div class="mui-switch-handle"></div>
				</div>
			</div>
			<div id="" class="chapter_content_cell weui_cell video_cell "> 
				<p class="chapter_cell_icon tests_untest" alt=""><p>
            	<div class="download_progress"></div>
                <div class="weui_cell_hd"><img src=""></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <label class="chapter_title">视频课程</label>
                    <label class="chapter_time">8分钟</label>
                </div>
                <div>
	                <a href="#" class="weui_btn weui_btn_mini right-btn">发布</a>
	                <div class="mui-switch mui-switch-mini mui-active right-switch">
						<div class="mui-switch-handle"></div>
					</div>
                	<a href="#" class="weui_btn weui_btn_mini right-btn">审阅</a>
                </div>
            </div>
            <div id="" class="chapter_content_cell weui_cell video_cell"> 
				<p class="chapter_cell_icon tests_untest" alt=""><p>
            	<div class="download_progress"></div>
                <div class="weui_cell_hd"><img src=""></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <label class="chapter_title">视频课程</label>
                    <label class="chapter_time">8分钟</label>
                </div>
                <div>
	                <div class="mui-switch mui-switch-mini right-switch">
						<div class="mui-switch-handle"></div>
					</div>
                	<a href="#" class="weui_btn weui_btn_mini right-btn">审阅</a>
                </div>
            </div> -->

		</div>
	</div>
	<div class="blank-div" hidden="hidden"></div>
	<div class="footer-view" hidden="hidden">
		<button id="study_btn" type="button" onclick="onExamClick()" class="mui-btn mui-btn-block">批改考核</button>
	</div>
	<!-- <div id="menu_btn" class="add-btn-div" onclick="menuClick()">
		<img class="add-btn" src="../../image/add_btn.png">
	</div> -->
</body>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/mui.min.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<!-- <script type="text/javascript" src="../../script/databaseOperation.js"></script> -->
<script type="text/javascript" src="../../script/study_courseTimeRecord.js"></script>
<script type="text/javascript" src="../../script/getToken.js"></script>
<script type="text/javascript">
	var chapterDatas = new Array();
	apiready = function(){
	    loadData();
	    setRefreshHeader();
	    setupNotifi();
//	     setupExamBtn();
	}
//	function setupExamBtn(){
//		var pageParam = api.pageParam;
//		var examid = pageParam.examid;
//		if(examid != null && examid != ''){
//			$('.blank-div').show();
//			$('.footer-view').show();
//		}else{
//			$('.blank-div').hide();
//			$('.footer-view').hide();
//		}
//	}
	function setupNotifi(){
		api.addEventListener({
		    name: 'closeMenuNotifi'
		}, function(ret, err) {
		    api.closeFrame({
		        name: 'course_add_menu'
		    });
		    $('#menu_btn').show();
		});
		api.addEventListener({
		    name: 'baiduWebVideoBackNotifi'
		}, function(ret, err) {
			var vid = ret.value.vid;
          	sendBuriedNotifi('1', 'mooc视频', '009',vid);
		});
	}
	function onExamClick(){
		api.openWin({useWKWebView:true,
		    name: 'Teacher_CourseTestMakingWindow',
		    url: 'Teacher_CourseTestMakingWindow.html',
		    pageParam: {
		        cid : api.pageParam.courseid,
		        pid : api.pageParam.planid,
		        examid : api.pageParam.examid
		    }
		});
	}
	//下拉刷新
	function setRefreshHeader() {
		api.setRefreshHeaderInfo({
			visible : true,
			bgColor : '#ccc',
			textColor : '#fff',
			textDown : '下拉刷新...',
			textUp : '松开刷新...',
			showTime : true
		}, function(ret, err) {
			loadData();
		});
	}
	function loadData(){
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '加载中...',
		    text: '',
		    modal: false
		});
		var params = {
			cid : api.pageParam.courseid
		};

		cfnetppPOST(url_freeChapterUrlNew, params, true, function(data, status){
			api.hideProgress();
			api.refreshHeaderLoadDone();
			if (status == 'success') {
				if (data.status == true) {
					var chapterlist = data.data;
					if (chapterlist.constructor == Array && chapterlist.length > 0) {
						chapterDatas = chapterlist;
						setuplist(chapterlist);
						if(api.pageParam.isNewTrain){
							$('.pub_btn').hide();
						}
						$('.noDataDiv').hide();
			    		$('.noInternetDiv').hide();
					}else{
						$('.noDataDiv').show();
		    			$('.noInternetDiv').hide();
					}
				}else{
					$('.noDataDiv').show();
	    			$('.noInternetDiv').hide();
				}
			}else{
				$('.noDataDiv').hide();
    			$('.noInternetDiv').show();
			}
		});
	}
	function setuplist(chapterlist){
		var chapterHtmlString = '';
		var pid = api.pageParam.planid;
		var chapterClassIndex = 0;
		var chapterSectionIndex = 0;
		var subChapterIndex = 0;
		for (var i = 0; i < chapterlist.length; i++) {
			var chapterData = chapterlist[i];
			if (chapterData.content_type == 'tag') {
				chapterClassIndex++;
			}else if(chapterData.content_type == 'part'){
				chapterSectionIndex++;
			}else{
				subChapterIndex++;
			}
			chapterHtmlString += chapterHtml(chapterData, i, chapterClassIndex, chapterSectionIndex, subChapterIndex);
		}
		$('#chapter_content').html(chapterHtmlString);
		addCellClick();
	}
	function addCellClick(){
		//阅卷按钮
		$('.test_btn').unbind('click');
		$('.test_btn').click(function(event){
		   	sendBuriedNotifi('1', 'mooc章节列表', '008','');
			event.stopPropagation();
			var vid = $(this).attr('vid');
			var bewrite = $(this).attr('bewrite');
			var is_dis_bewrite = $(this).attr('is_dis_bewrite');
			var title = $(this).attr('title');
			api.openWin({useWKWebView:true,
			    name: 'Teacher_TestMarkingManageWindow',
			    url: '../Teacher_Teach/Teacher_TestMarkingManageWindow.html',
			    pageParam: {
			        vid: vid,
			        pid: api.pageParam.planid,
			        cid: api.pageParam.courseid,
			        bewrite: bewrite,
			        is_dis_bewrite: is_dis_bewrite,
			        title: title,
			        type:0,//mocc
			        sourceurl : window.location.pathname,
					sourcetitle : document.title,
			    }
			});
			
		});
		//发布/取消发布按钮
		$('.pub_btn').unbind('click');
		$('.pub_btn').click(function(event){
		
			var vid = $(this).attr('vid');
			var isclose = $(this).attr('isclose');
			var name = $(this).attr('name');
			var pubClass = $(this).attr('pubClass');
			
			var pubStatus = 1;//发布
			if (isclose == 1) {//已发布
				pubStatus = 0;//取消发布
				$(this).removeClass('mui-active');
			}else{
				$(this).addClass('mui-active');
			}
			pubZhangJie(vid, pubStatus, pubClass,name);
			event.stopPropagation();
		});
		//点击cell
		$('.chapter_content_cell').unbind('click');
		$('.chapter_content_cell').click(function(){
			$('.chapter_content_cell').removeClass('base_style_text_color');
			$(this).addClass('base_style_text_color');
			var index = $(this).attr('index');
			var chapterData = chapterDatas[parseInt(index)];
			pushNextWindow(chapterData);
		});
		//点击章
		$('.zhang_cell').unbind('click');
		$('.zhang_cell').click(function(){
			var chapterClassName = $(this).attr('value');
			if ($(this).hasClass('hideAll')) {
				$('.' + chapterClassName).show(0);
				$(this).removeClass('hideAll');
			}else{
				$('.' + chapterClassName).hide(0);
				$(this).addClass('hideAll');
			}
		});
		//点击节
		$('.jie_cell').unbind('click');
		$('.jie_cell').click(function(){
			var chapterSectionName = $(this).attr('value');
			$('.' + chapterSectionName).toggle(0);
		});
	}
	function pushNextWindow(chapter){
	  	sendBuriedNotifi('1', 'mooc章节列表', '008','');
		var contentType = chapter.content_type;
		var pushParams = '';
		var winName = '';
		var title = decodeURIComponent(chapter.cdetailtitle);
		var pid = api.pageParam.planid;
		var vid = chapter.id;
		var cid =  api.pageParam.courseid;
		var rid = chapter.rid;
		var bewrite = chapter.bewrite;
		var other = chapter.other;
		var is_encr = chapter.is_encr;
		var baidu_cloud_id_url = chapter.baidu_cloud_id_url;
		var baidu_cloud_id = chapter.baidu_cloud_id;
		var sourceUrl  = chapter.sourceUrl;
		if (contentType == 'doc') {//文档
			if (is_encr == 1) {//加密
				// var CFBaiDuDoc = api.require('CFBaiDuDoc');
		  //       CFBaiDuDoc.startDocActivityForResult({
		  //           docId:baidu_cloud_id,//文档ID
		  //           title:title,//文档标题
		  //           token:"TOKEN",//文档token，离线加载时不验证。
		  //           host:"BCEDOC",//文档所属站点
		  //           docType:"doc" //文档类型，可取值为ppt 和 doc
		  //       },function(){
		  //       });
				api.openWin({useWKWebView:true,
				    name: 'StudyWebBaiDuDoc_win',
				    url: '../Study/StudyWebBaiDuDoc_win.html',
				    pageParam: {
				        docId: baidu_cloud_id,
				        title: title
				    }
				});
		        return;
			}else{
				pushParams = {
					title : title,
					doc : rid,
					pushType : 'teacher',
					sourceurl : window.location.pathname,
				   sourcetitle : document.title,
				};
				winName = 'studyCourseDoc';
			}
		}else if(contentType == 'video'){//视频
			getCourseUrl(chapter);
			return;
		}else if(contentType == 'richtext'){//富文本
			pushParams = {
				cdetailtitle : title,
		    	other : other,
		    	vid : vid,
		    	cid : cid,
		    	pid : pid,
		    	richtextType : 2,
		    	bewrite : bewrite,
		    	sourceurl : window.location.pathname,
				sourcetitle : document.title,
			};
			winName = 'studyCourseRichtextNew';
		}else if(contentType == 'tests'){//测验
			api.openWin({useWKWebView:true,
			    name: 'Teacher_Freecourse_TestChapter',
			    url: 'Teacher_Freecourse_TestChapter.html',
			    pageParam: {
			        id : vid,
					pid : pid,
					cid : cid,
					cdetailtitle : title,
					rid : rid,
					bewrite : bewrite,
					is_dis_bewrite : chapter.is_dis_bewrite,
					type:0,//mocc
					sourceurl : window.location.pathname,
					sourcetitle : document.title,
			    }
			});
			// pushParams = {
			// 	chapterid : vid,
			// 	pid : pid,
			// 	cid : cid,
			// 	title : title,
			// 	rid : rid
			// };
			// winName = 'New_student_study_freecourse_TestExam';
			// api.openWin({useWKWebView:true,
			//     name: winName,
			//     url: '../Study/' + winName + '.html',
			//     bounces: false,
			//     pageParam: pushParams,
			//     bgColor: '#fff',
			//     slidBackEnabled :false
			// });
			return;
		}else if(contentType == 'discuss'){//讨论
			pushParams = {
			    chapterid : vid,
				pid : pid,
				cid : cid,
				title : title,
				rid : rid,
				bewrite :bewrite,
				type :0,
				sourceurl : window.location.pathname,
				sourcetitle : document.title,
		    };
		    winName = 'Student_Mocc_DiscussChapterWindow';
		}else if(contentType == 'hdresource'){
			pushParams = {
			    id : vid,
				pid : pid,
				cid : cid,
				title : title,
				rid : rid,
				bewrite :bewrite,
				type :0,
				hdresourceType:1,
				ismocc:1,
				sourceurl : window.location.pathname,
				sourcetitle : document.title
		    };
			winName = 'student_study_freecourse_interactiveNew';
		}else if(contentType=='works'){
			api.openWin({useWKWebView:true,
				name: 'Teach_Freecouse_check_homeWork',
				url: 'Teach_Freecouse_check_homeWork.html',
				pageParam: {
					pid : pid,
					vid : vid,
					cid : api.pageParam.courseid,
					wid : rid,
					sourceurl : window.location.pathname,
					sourcetitle : document.title

				}
			});
		}else{
			return;	
		}
		api.openWin({useWKWebView:true,
		    name: winName,
		    url: '../Study/' + winName + '.html',
		    bounces: false,
		    pageParam: pushParams,
		    bgColor: '#fff'
		});
	}
	function sendBuriedNotifi(busionessid,pagetype,pagetypeid,vid){
	    var userinfo = {
			uid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjxid'),
			uname : $api.getStorage('cfnetppusername'),
			cid : api.pageParam.courseid,
			pid : api.pageParam.planid,
		}
		var data = {
			busionessid : busionessid,
			pagetype : pagetype,
			pagetypeid : pagetypeid,
			sourceurl : api.pageParam.sourceurl,
			sourcetitle : api.pageParam.sourcetitle,
			accesspageurl :  window.location.pathname,
			accesspagetitle : document.title,
			userinfo : userinfo
		}
	   if(vid!=""){
	     	userinfo["vid"]=vid;
	     	data["accesspagetitle"]="Mocc视频章节";
	   	}	
		SendBehaviorTrajectoriesNotifi_Study(data);
	}


	function pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, path, title,vid){
       	sendBuriedNotifi('0', 'mooc视频', '009',vid);
		if(path != null && path != '' && path.indexOf("http://") < 0 ){
			path = 'http://bos.cfnet.org.cn' + path;
		} 
		var videoPath = path;
 		if (is_encr == 2) {//转码
			videoPath = baidu_cloud_id_url;
			api.openWin({useWKWebView:true,
	 		    name: 'BaiDuWebVideo',
	 		    url: '../Study/BaiDuWebVideo.html',
	 		    pageParam: {
	 		    	title: title,
	 		        url: videoPath,
	 		        token: '',
	 		        vid: vid
	 		    },
	 		    slidBackEnabled: false
	 		});
		}else{
			api.openWin({useWKWebView:true,
	 		    name: 'BaiDuWebVideo',
	 		    url: '../Study/BaiDuWebVideo.html',
	 		    pageParam: {
	 		    	title: title,
	 		        url: videoPath,
	 		        token: '',
	 		        vid: vid
	 		    },
	 		    slidBackEnabled: false
	 		});
		}
		// if (path != '') {
		// 	var CFBaiDuVideo = api.require('CFBaiDuVideo');
		//     CFBaiDuVideo.initVideo({
		//        title : title,
		//        path : videoPath,
		//        isShowFullScreenBtn : 1,
		//        isShowFullScreen : 1,
		//        token : ''
		//     },function(ret, err){
		//      	sendBuriedNotifi('1', 'mooc视频', '009',vid);
		//     });
		// }else{
		// 	if (is_encr == 1 || is_encr == 2) {//加密
		// 		videoPath = baidu_cloud_id_url;
		// 		getVideoToken(function(status, videoToken){
		// 			var CFBaiDuVideo = api.require('CFBaiDuVideo');
		// 	        CFBaiDuVideo.initVideo({
		// 	           title : title,
		// 	           path : videoPath,
		// 	           isShowFullScreenBtn : 1,
		// 	           isShowFullScreen : 1,
		// 	           token : videoToken
		// 	        },function(ret, err){
		// 	        	sendBuriedNotifi('1', 'mooc视频', '009',vid);
		// 	        });
		// 	    });
		// 	}else{
		// 		api.toast({
		// 		    msg: '视频播放失败！'
		// 		});
		// 	}
		// }
	}
	
	
	
	function toPlayVideo(path, title){
		// var h = api.winWidth * 3 / 4;
		var h = 240;
		api.openFrame({
		    name: 'HTML5VideoPlayer',
		    url: '../Teacher_Teach/HTML5VideoPlayer.html',
		    rect: {
		        x: 0,
		        y: 0,
		        w: 'auto',
		        h: h
		    },
		    pageParam:{
		    	videoUrl : path
		    },
		    reload : true
		});
		return;
		var videoPlayer = api.require('videoPlayer');
		videoPlayer.play({
		    path : path,
		    texts: {
		        head: {
		            title: title
		        }
		    },
		    styles : {
		    	head : {
		    		backSize : 24,
		    		backImg : 'widget://image/vp_back.png',
		    		setSize : 24,
		    		setImg : 'widget://image/vp_more.png'
		    	},
		    	foot :{
		    		playSize : 24,
		    		playImg : 'widget://image/vp_play.png',
		    		pauseImg : 'widget://image/vp_pause.png',
		    		nextSize : 24,
		    		nextImg : 'widget://image/vp_next.png'
		    	}
		    }
		}, function(ret, err) {
		});
	}

	function chapterHtml(chapter, index, chapterClassIndex, chapterSectionIndex, subChapterIndex){
		var chapterTime = chapter.ctime;
		if (chapterTime == 0) {
			chapterTime = '';
		}else{
			chapterTime += '分钟';
		}
		var contentType = chapter.content_type;
 		var chapterClassName = 'chapter' + chapterClassIndex;
 		var chapterSectionName = chapterClassName + chapterSectionIndex;
 		var keshiClass = " " + chapterClassName + " " + chapterSectionName;
 		var title = decodeURIComponent(chapter.cdetailtitle);
 		var id = chapter.id;
 		var isclose = chapter.isclose;
 		var pubClass1 = 'pubClass' + chapterClassIndex;
 		var pubClass2 = pubClass1 + chapterSectionIndex;
 		var pubClass3 = pubClass1 + " " + pubClass2;
 		if (chapterSectionIndex == 0) {
 			pubClass3 = pubClass1;
 		}
 		var pubClass4 = pubClass2 + subChapterIndex;
 		var pubClass5 = pubClass3 + " " + pubClass4;
 		// var pubHtml = '<a href="#" id="pubBtn'+id+'" vid="'+id+'" index="'+index+'" isclose="'+isclose+'" class="pub_btn weui_btn weui_btn_mini right-btn">发布</a>';
 		var pubHtml = '<div pubClass="'+pubClass5+'" href="#" id="pubBtn'+id+'" vid="'+id+'" index="'+index+'" isclose="'+isclose+'" name="'+title+'" class="pub_btn mui-switch mui-switch-mini right-switch '+pubClass5+'">'+
						'<div class="mui-switch-handle"></div>'+
					'</div>';
		var muiActiveClass = '';
 		if (isclose == 1) {
 			// pubHtml = '<a href="#" id="pubBtn'+id+'" vid="'+id+'" index="'+index+'" isclose="'+isclose+'" class="pub_btn weui_btn weui_btn_mini right-btn right-btn-cancel">取消发布</a>';
 			pubHtml = '<div pubClass="'+pubClass5+'" href="#" id="pubBtn'+id+'" vid="'+id+'" index="'+index+'" isclose="'+isclose+'" name="'+title+'" class="pub_btn mui-switch mui-switch-mini mui-active right-switch '+pubClass5+'">'+
						'<div class="mui-switch-handle"></div>'+
					'</div>';
			muiActiveClass = ' mui-active';
 		}
 		var testHtml = '';
 		var studyStatusClass = '';
 		if (contentType == 'tag') {//章

 			return '<div id="'+id+'" class="weui_panel_hd list_section_contnt zhang_cell" value="'+chapterClassName+'"><span class="title-span">'+
 					title+
 					'</span><div pubClass="'+pubClass1+'" href="#" id="pubBtn'+id+'" vid="'+id+'" index="'+index+'" isclose="'+isclose+'" name="'+title+'" class="pub_btn mui-switch mui-switch-mini right-switch '+pubClass1+muiActiveClass+'">'+
						'<div class="mui-switch-handle"></div>'+
					'</div>'+
				// '<span class="cell-right-arrow arrow-right"></span>\
			'</div>';
		}else if(contentType == 'part'){//节
			// return "<div class='weui_cell part-cell jie_cell "+chapterClassName+"' value='"+chapterSectionName+"'>"+
   //              "<div class='weui_cell_bd weui_cell_primary'>"+
   //                  "<p class='part-title'>"+title+"</p>"+
   //              "</div>"+
   //          "</div>";
			return '<div class="weui_cell jie_cell weui_cells_title '+chapterClassName+'" value="'+chapterSectionName+'"><span class="title-span">'+title+'</span><div pubClass="'+pubClass3+'" href="#" id="pubBtn'+id+'" vid="'+id+'" index="'+index+'" isclose="'+isclose+'"  class="pub_btn mui-switch mui-switch-mini right-switch '+pubClass3+muiActiveClass+'">'+
						'<div class="mui-switch-handle"></div>'+
					'</div>'+'</div>';
		}else if(contentType == 'catetag'){
			return '<div class="weui_cell jie_cell weui_cells_title '+chapterClassName+'" value="'+chapterSectionName+'"><span style="margin-left: 15px;color: #F8575D" class="title-span">'+title+'</span><div pubClass="'+pubClass3+'" href="#" id="pubBtn'+id+'" vid="'+id+'" index="'+index+'" isclose="'+isclose+'"  class="pub_btn mui-switch mui-switch-mini right-switch '+pubClass3+muiActiveClass+'">'+
					'<div class="mui-switch-handle"></div>'+
					'</div>'+'</div>'
		}else if(contentType == 'doc'){//文档
			keshiClass = ' doc_cell' + keshiClass;
			studyStatusClass = ' doc_unstudy';
		}else if(contentType == 'video'){//视频
			studyStatusClass = ' video_unstudy';
		}else if (contentType == 'richtext'){//富文本
			studyStatusClass = ' richtext_unstudy';
		}else if (contentType == 'tests'){//测验
			testHtml = '<a href="#" vid="'+id+'" "is_dis_bewrite="'+chapter.is_dis_bewrite+'"bewrite="'+chapter.bewrite+'"  title="'+chapter.title+'" index="'+index+'" name="'+title+'" class="test_btn weui_btn weui_btn_mini right-btn">批卷</a>';
			studyStatusClass = ' tests_untest';
		}else if(contentType == 'discuss'){//讨论
			studyStatusClass = ' taolun_normal';
		}else if(contentType == 'hdresource'){//互动资源
			studyStatusClass = ' ziyuan_unstudy';
		}else if(contentType == 'works'){
			studyStatusClass = ' works';
		}else{
			return '';
		}
		return '<div id="'+id+'" index="'+index+'" class="chapter_content_cell weui_cell'+keshiClass+'">'+
				'<p class="chapter_cell_icon'+studyStatusClass+'" alt=""><p>'+
            	'<div class="download_progress"></div>'+
                '<div class="weui_cell_hd"><img src=""></div>'+
                '<div class="weui_cell_bd weui_cell_primary">'+
                    '<label class="chapter_title">'+title+'</label>'+
                    '<label class="chapter_time">'+chapterTime+'</label>'+
                '</div>'+
                '<div>'+
	                pubHtml+
                	testHtml+
                '</div>'+
            '</div>';
	}
	
//	//测验阅卷
//	function openTest(){
//	}
	//发布章节
	function pubZhangJie(vid, pubStatus, pubClass,name){
		var pubParams = {
			jid : $api.getStorage('cfnetppjxid'),
			uid : $api.getStorage('cfnetppuid'),
			cid : api.pageParam.courseid,
			vid : vid,
			isclose : pubStatus
		};

		var pubClassArr = pubClass.split(" ");
		var lastPubClass = pubClassArr[pubClassArr.length - 1];//最后一个
		var previousPubClass = pubClassArr[pubClassArr.length - 2];//倒数第二个
		cfnetppPOST(url_closeOfOpenChapter, pubParams, false, function(data, status){
		    if(pubStatus==1){//关闭当前章节
				SendBusinessOperationsLogNotifi('Mocc课程列表页', '028', pubParams, pubParams, '', data, 'Mocc课程关闭章节接口', '006-01')
			}else{
				SendBusinessOperationsLogNotifi('Mocc课程列表页', '028', pubParams, pubParams, '', data, 'Mocc课程开启章节接口', '006-02')
			}
			if (status == 'success') {
				if (data.code == 200) {
					api.toast({
					    msg: '操作成功'
					});
					if (pubStatus == 0) {//取消发布
						// $('#pubBtn' + vid).attr('isclose', '0');
						// $('#pubBtn' + vid).removeClass('right-btn-cancel');
						// $('#pubBtn' + vid).text('发布');
						// $('#pubBtn' + vid).removeClass('mui-active');
						$('.'+lastPubClass).attr('isclose', '0');
						$('.'+lastPubClass).removeClass('mui-active');
						var allCloseStatus = 0;
						var j = 0;
						$('.' + previousPubClass).each(function(){
							if($(this).attr('isclose') == '1'){
								if (j > 0) {
									allCloseStatus++;
								}
								j++;
							}
						});
						if (allCloseStatus == 0) {
							// $('.'+previousPubClass).attr('isclose', '0');
							// $('.'+previousPubClass).removeClass('mui-active');
						}
					}else{
						// $('#pubBtn' + vid).attr('isclose', '1');
						// $('#pubBtn' + vid).addClass('right-btn-cancel');
						// $('#pubBtn' + vid).text('取消发布');
						// $('#pubBtn' + vid).addClass('mui-active');
						$('.'+lastPubClass).attr('isclose', '1');
						$('.'+lastPubClass).addClass('mui-active');
						var allCloseStatus = 0;
						var j = 0;
						$('.' + previousPubClass).each(function(){
							if($(this).attr('isclose') == '0'){
								if (j > 0) {
									allCloseStatus++;
								}
								j++;
							}
						});
						if (allCloseStatus == 0) {
							// $('.'+previousPubClass).attr('isclose', '1');
							// $('.'+previousPubClass).addClass('mui-active');
						}
					}
				}else{
					api.toast({
					    msg: '操作失败，请重试'
					});
					//操作失败则复原
					if (pubStatus == 0) {//取消发布
						$('#pubBtn' + vid).addClass('mui-active');
					}else{
						$('#pubBtn' + vid).removeClass('mui-active');
					}
				}
			}else{
				api.toast({
				    msg: '操作失败，请重试'
				});
				//操作失败则复原
				if (pubStatus == 0) {//取消发布
					$('#pubBtn' + vid).addClass('mui-active');
				}else{
					$('#pubBtn' + vid).removeClass('mui-active');
				}
			}
		});
	}
	function menuClick(){
		$('#menu_btn').hide();
		api.openFrame({
		    name: 'course_add_menu',
		    url: '../Study/course_add_menu.html',
		    rect: {
		        x: 0,
		        y: 0,
		        w: 'auto',
		        h: 'auto'
		    },
		    pageParam: {
		        name: api.pageParam
		    }
		});
	}
	function getCourseUrl(chapter) {
		cfnetppPOST(url_getCourseUrl, {"vid": chapter.id}, false, function (data, status) {
			if(data.status){
				chapter.sourceurl=data.data.sourceUrl;
				chapter.baidu_cloud_id_url=data.data.baidu_cloud_id_url;
				openVideo(chapter);
			}
		})
	}
	function openVideo(chapter) {
		var vid = chapter.id;
		var rid = chapter.rid;
		var sourceUrl  = chapter.sourceUrl;
		var is_encr = chapter.is_encr;
		var baidu_cloud_id_url = chapter.baidu_cloud_id_url;
		var title = decodeURIComponent(chapter.cdetailtitle);
		if (sourceUrl != null && sourceUrl != '' && sourceUrl.indexOf("http://") >= 0) {
			rid = sourceUrl;
		}
		var connectionType = api.connectionType;
		if (connectionType != 'wifi' && connectionType != 'none') {
			api.confirm({
				title: '提示',
				msg: '您当前处于移动数据网络下，是否继续播放',
				buttons: ['确定', '取消']
			}, function(ret, err) {
				var index = ret.buttonIndex;
				if (index == 1) {//确定
					// toPlayVideo(rid, title);
					pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, rid, title,vid);
				}
			});
		}else{
			// toPlayVideo(rid, title);
			pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, rid, title,vid);
		}
	}
</script>
</html>